import { createStore } from 'vuex'
import persist from 'vuex-persistedstate';
export default createStore({
  state: {
    carList:[], // 购物车的数据
  },
  mutations: {
    addCart(state,val){ // 加入购物车
      // console.log(val);
      let index = state.carList.findIndex(item => item.checkId == val.checkId);
      if (index>-1){
        state.carList[index].num+=val.num;
      } else {
        state.carList.push(val)
      }
      
    }

  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new persist({
      storage: window.localStorage,
    }),
  ]
})
